package com.missilike.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.missilike.biz.IMilJournalService;
import com.missilike.core.result.CommonResult;
import com.missilike.core.utils.ResultUtils;
import com.missilike.core.utils.SecurityUtils;
import com.missilike.domain.request.MilJournalDetailForm;
import com.missilike.domain.response.MilJournalInfo;
import com.missilike.repository.entity.MilJournal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 期刊 前端控制器
 * </p>
 *
 * @author kin
 * @since 2019-01-14
 */
@RestController
@RequestMapping("/api/mil/journal")
public class MilJournalController {

    private final IMilJournalService milJournalService;

    @Autowired
    public MilJournalController(IMilJournalService milJournalService) {
        this.milJournalService = milJournalService;
    }

    @RequestMapping(value = "page", method = RequestMethod.GET)
    public CommonResult list(@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize) {
        IPage<MilJournalInfo> journalList = milJournalService.getList(new Page<>(pageNum, pageSize));
        return ResultUtils.ok(journalList);
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public CommonResult save(@RequestBody MilJournal milJournal) {
        milJournal.setCreateUserId(SecurityUtils.getCurrentUserId());
        milJournalService.save(milJournal);
        return ResultUtils.ok();
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public CommonResult update(@RequestBody MilJournal milJournal) {
        milJournalService.updateById(milJournal);
        return ResultUtils.ok();
    }
}

